package com.appbee.gdata.picasaadmin.client.ui;

import javax.inject.Inject;

import com.appbee.core.client.ui.IMessageView;
import com.appbee.core.client.ui.MessageView;
import com.appbee.gdata.picasaadmin.client.activity.PicasaSettingsActivity;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class SettingsView extends Composite implements
		PicasaSettingsActivity.View
{
	@UiField(provided = true)
	MessageView messageView;

	@UiField
	TextBox userName;

	@UiField
	PasswordTextBox password;

	@UiField
	Button btSave;

	@UiField
	Button btFlush;

	private static SettingsViewUiBinder uiBinder = GWT
			.create(SettingsViewUiBinder.class);

	private PicasaSettingsActivity settingsActivity;

	interface SettingsViewUiBinder extends UiBinder<Widget, SettingsView>
	{
	}

	@Inject
	public SettingsView(MessageView messageView)
	{
		this.messageView = messageView;
		initWidget(uiBinder.createAndBindUi(this));
		btSave.addClickHandler(new ClickHandler()
		{

			@Override
			public void onClick(ClickEvent event)
			{
				settingsActivity.onSave();
			}
		});

		btFlush.addClickHandler(new ClickHandler()
		{

			@Override
			public void onClick(ClickEvent event)
			{
				settingsActivity.onFlushCache();
			}
		});
	}

	@Override
	public void setActivity(PicasaSettingsActivity picasaSettingsActivity)
	{
		this.settingsActivity = picasaSettingsActivity;
	}

	@Override
	public void setUserName(String response)
	{
		userName.setValue(response);
	}

	@Override
	public String getPassword()
	{
		return password.getValue();
	}

	@Override
	public String getUserName()
	{
		return userName.getValue();
	}

	@Override
	public IMessageView getMessageView()
	{
		return messageView;
	}


}
